﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using messageboard.bll;

namespace messageboard.admin
{
    public partial class messagemanage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {//判断是否管理员登录
            if (Session["name"] == null)
            {
                Label1.Text = "您无权查看该网页";
                login.Visible = true;
            }
            else if (Session["name"].ToString() != "admin")
            {
                Label1.Text = "您无权查看该网页";
                login.Visible = true;
            }

            else if (!IsPostBack)
            {//数据绑定
                login.Visible = false;
                GridView1.DataSource = new MessageBll().showmessage();
                GridView1.DataBind();
            }
            
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //删除留言
            int a = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
            MessageBll bll = new MessageBll();
            bll.deletemessage(a);

            Response.Redirect("messagemanage.aspx");

        }

        protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            Label1.Text = "删除成功";
           

        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {//PageIndexChanging事件
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource = new MessageBll().showmessage();
            DataBind();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}